<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%form_input}}".
 *
 * @property integer $id
 * @property integer $sort
 * @property string $type
 * @property string $label
 * @property string $options
 * @property string $default_value
 * @property integer $ismust
 * @property integer $form_id
 *
 * @property Form $form
 */
class FormInput extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%form_input}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['sort', 'ismust', 'form_id'], 'integer'],
            [['type', 'label', 'form_id'], 'required'],
            [['type', 'label'], 'string', 'max' => 45],
            [['options', 'default_value'], 'string', 'max' => 128],
            [['form_id'], 'exist', 'skipOnError' => true, 'targetClass' => Form::className(), 'targetAttribute' => ['form_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'sort' => '排序',
            'type' => '类型',
            'label' => 'Label',
            'options' => '选项',
            'default_value' => '默认值',
            'ismust' => '必填',
            'form_id' => '表单',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getForm()
    {
        return $this->hasOne(Form::className(), ['id' => 'form_id']);
    }
}
